package com.hhh.springai_test.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hhh.springai_test.common.BaseResponse;
import com.hhh.springai_test.common.ResultUtils;
import com.hhh.springai_test.constant.UserConstant;
import com.hhh.springai_test.model.dto.readingRoom.AddReadingRoomRequest;
import com.hhh.springai_test.model.dto.readingRoom.UpdateReadingRoomRequest;
import com.hhh.springai_test.model.po.ReadingRoom;
import com.hhh.springai_test.model.po.ReadingRoomReservation;
import com.hhh.springai_test.service.ReadingRoomReservationService;
import com.hhh.springai_test.service.ReadingRoomService;
import cn.dev33.satoken.annotation.SaCheckRole;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/readingRoom")
public class ReadingRoomController {

    @Resource
    private ReadingRoomService readingRoomService;

    @Resource
    private ReadingRoomReservationService readingRoomReservationService;

    /**
     * 添加阅览室
     * @param addReadingRoomRequest
     * @return
     */
    @PostMapping("/add")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Long> addReadingRoom(@RequestBody AddReadingRoomRequest addReadingRoomRequest) {
        long result = readingRoomService.addReadingRoom(addReadingRoomRequest);
        return ResultUtils.success(result);
    }

    /**
     * 删除阅览室
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> deleteReadingRoom(@PathVariable Long id) {
        boolean result = readingRoomService.deleteReadingRoom(id);
        return ResultUtils.success(result);
    }

    /**
     * 更新阅览室
     * @param updateReadingRoomRequest
     * @return
     */
    @PostMapping("/update")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> updateReadingRoom(@RequestBody UpdateReadingRoomRequest updateReadingRoomRequest) {
        boolean result = readingRoomService.updateReadingRoom(updateReadingRoomRequest);
        return ResultUtils.success(result);
    }

    /**
     * 获取阅览室列表
     * @return
     */
    @GetMapping("/list")
    public BaseResponse<List<ReadingRoom>> listReadingRoom() {
        List<ReadingRoom> readingRoomList = readingRoomService.list();
        return ResultUtils.success(readingRoomList);
    }

    /**
     * 根据id获取阅览室信息
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public BaseResponse<ReadingRoom> getReadingRoomById(@PathVariable Long id) {
        ReadingRoom readingRoom = readingRoomService.getReadingRoomById(id);
        return ResultUtils.success(readingRoom);
    }

}
